Monkey Documentation

First Monkey steps

Skid spills some source...

Main

We begin with the smallest monkey program.

Function Main()
    Print "Hello"
End
In which, with the HTML5 target selected, we verify we are able to create and view our monkey developments.

To learn more about the Main entry point of a program make sure you read the Programs and Declarations section of the Language reference.

Game App

We now build a mojo App which we call Game (in monkey class names are typically capitalized).

Import mojo

Class Game Extends App
    
    Method OnCreate()
        Print "hello"
    End
    
End

Function Main()
    New Game()
End

A mojo App is used to provide us methods of input, graphics and sound. The framework above creates a single App using the Game class definition.

Spiral animation

With our game object defined we extend the basic Update and Render parts of the app.

The minimum requirements for an animating monkey application are an App implementing the methods:

The following draws an animated spiral shape using the DrawPoint command.

Import mojo

Class Game Extends App

    ' radial sprial with axis aligned phase
        
    Function DrawSpiral(clock)
        Local w=DeviceWidth/2
        For Local i#=0 Until w*1.5 Step .2
            Local x#,y#
            x=w+i*Sin(i*3+clock)
            y=w+i*Cos(i*2+clock)
            DrawPoint x,y
        Next
    End

    Field updateCount
    
    Method OnCreate()
        Print "spiral"
        
        SetUpdateRate 60
    End
    
    Method OnUpdate()
        updateCount+=1
    End
        
    Method OnRender()
        Cls
        DrawSpiral updateCount
        DrawSpiral updateCount*1.1
    End
    
End

Function Main()
    New Game()
End

Each spiral drawn by the program begins at the middle of the screen and spirals out using the Maths functions Sin and Cos.

Here is the final application: